import ts from 'rollup-plugin-typescript2'
import path from 'path'
import { dts } from 'rollup-plugin-dts'
import { fileURLToPath } from 'url'
import { nodeResolve } from '@rollup/plugin-node-resolve'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.resolve(__filename)

export default [
    {
        input: './src/core/index.ts',
        output: [
            {
                file: path.resolve(__dirname, '../dist/index.esm.js'),
                format: 'es'
            },
            {
                file: path.resolve(__dirname, '../dist/index.cjs.js'),
                format: 'cjs'
            },
            {
                input: './src/core/index.ts',
                file: path.resolve(__dirname, '../dist/index.js'),
                format: 'umd',
                name: 'tracker'
            }
        ],
        plugins: [
            ts(),
            nodeResolve({
                customResloveOptions: {
                    alias: {
                        '@': './src'
                    }
                }
            })
        ]
    },
    {
        // 打包声明文件
        input: './src/core/index.ts',
        output: {
            file: path.resolve(__dirname, '../dist/index.d.ts'),
            format: 'es'
        },
        plugins: [
            dts(),
            nodeResolve({
                customResloveOptions: {
                    alias: {
                        '@': './src'
                    }
                }
            })
        ]
    }
]